package org.feng.clog.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.feng.clog.LogId;

import java.util.Calendar;
import java.util.Locale;

/**
 * 返回结构vo
 *
 * @author feng
 */

@Data
public class ResultVo<T> {
    @JsonProperty(index = 1)
    private Integer errno;
    @JsonProperty(index = 2, value = "errmsg")
    private String errMsg;
    @JsonProperty(index = 3)
    private T data;
    @JsonProperty(index = 4)
    private String logId;
    @JsonProperty(index = 5, value = "st")
    private Long st;
    @JsonProperty(index = 6, value = "msg")
    private String msg;
    @JsonProperty(index = 7, value = "code")
    private Integer code;


    public ResultVo() {
    }

    public ResultVo(int errno) {
        this.errno = errno;
        this.code = errno;
        this.logId = LogId.get();
        this.st = Calendar.getInstance(Locale.CHINA).getTimeInMillis();
    }

    public ResultVo(int errno, T data) {
        this.errno = errno;
        this.code = errno;
        this.errMsg = "";
        this.msg = this.errMsg;
        this.data = data;
        this.logId = LogId.get();
        this.st = Calendar.getInstance(Locale.CHINA).getTimeInMillis();
    }

    public ResultVo(int errno, String message) {
        this.errno = errno;
        this.code = errno;
        this.errMsg = message;
        this.msg = message;
        this.data = null;
        this.logId = LogId.get();
        this.st = Calendar.getInstance(Locale.CHINA).getTimeInMillis();
    }
}
